import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Radio & Checkbox Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: RadioAndCheckboxPage(),
    );
  }
}

class RadioAndCheckboxPage extends StatefulWidget {
  @override
  _RadioAndCheckboxPageState createState() => _RadioAndCheckboxPageState();
}

class _RadioAndCheckboxPageState extends State<RadioAndCheckboxPage> {
  // Radio状态
  int _radioValue = 0;

  // Checkbox状态
  bool _checkboxValue1 = false;
  bool _checkboxValue2 = false;
  bool _checkboxValue3 = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Radio & Checkbox Demo')),
      body: Padding(
        padding: EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // Radio部分
            Text(
              'Radio示例:',
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            Row(
              children: [
                Radio(
                  value: 0,
                  groupValue: _radioValue,
                  onChanged: (value) {
                    setState(() {
                      _radioValue = value as int;
                    });
                  },
                ),
                Text('选项1'),
              ],
            ),
            Row(
              children: [
                Radio(
                  value: 1,
                  groupValue: _radioValue,
                  onChanged: (value) {
                    setState(() {
                      _radioValue = value as int;
                    });
                  },
                ),
                Text('选项2'),
              ],
            ),
            Row(
              children: [
                Radio(
                  value: 2,
                  groupValue: _radioValue,
                  onChanged: (value) {
                    setState(() {
                      _radioValue = value as int;
                    });
                  },
                ),
                Text('选项3'),
              ],
            ),
            SizedBox(height: 20),

            // Checkbox部分
            Text(
              'Checkbox示例:',
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            Row(
              children: [
                Checkbox(
                  value: _checkboxValue1,
                  onChanged: (value) {
                    setState(() {
                      _checkboxValue1 = value!;
                    });
                  },
                ),
                Text('选项A'),
              ],
            ),
            Row(
              children: [
                Checkbox(
                  value: _checkboxValue2,
                  onChanged: (value) {
                    setState(() {
                      _checkboxValue2 = value!;
                    });
                  },
                ),
                Text('选项B'),
              ],
            ),
            Row(
              children: [
                Checkbox(
                  value: _checkboxValue3,
                  onChanged: (value) {
                    setState(() {
                      _checkboxValue3 = value!;
                    });
                  },
                ),
                Text('选项C'),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
